package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏西西
 * Date: 2023-09-01
 * Time: 11:12
 */
class Singleton{
    //在此处先把这个实例创建出来
    private static Singleton instance = new Singleton();

    //如果需要使用这个唯一实例，统一通过Singleton.getInstance()方式来获取
    public static Singleton getInstance(){
        return instance;
    }
    //为了避免Singleton 类不小心被复制出多份来
    //把构造方法设置为private，在类外面，就无法通过new方式来创建这个Singleton实例了
    private Singleton(){

    }
}
public class ThreadDemo19 {
    public static void main(String[] args) {
        Singleton s = Singleton.getInstance();
        Singleton s1 = Singleton.getInstance();
        System.out.println(s == s1);
    }
}
